package testdemo.d1;

public class Well extends Thread {

    private static volatile int num = 0;

    private void countPlus() {

        for (; num < 100; ) {
            if (num < 0 || num > 100) {
                return;
            }

            synchronized (Well.class) {
                if (num < 100) {
                    num= num+1;
                }

            }
                if (num == 100) {
                    System.out.println("this thread" + this.getName() + "已操作完毕");
                } else {
                    System.out.println(
                            "当前线程是" + this.getName() + "在执行第" + num + "次操作\t" + "还剩" + (100 - num) + "次操作");
                }

            try {
                sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void run() {
        countPlus();
    }
}
